home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 15 / macformat_15.iso / C de cerca / Codewarrior Lite / MacOS Support / Headers / ANSI Headers / complex < prev    next >
Text File  |  1995-12-29  |  9KB  |  302 lines

  1. // complex standard header
  2. #ifndef _COMPLEX_
  3. #define _COMPLEX_
  4. #include <istream>
  5. #include <ostream>
  6. #include <math.h>
  7. #define __STD_COMPLEX
  8.  
  9. #if __MWERKS__
  10. #pragma options align=mac68k
  11.  
  12. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  13. #pragma import on
  14. #endif
  15. #endif
  16.  
  17.         // class float_complex
  18. class float_complex {
  19. public:
  20.     float_complex(float _R = 0, float _I = 0)
  21.         : _Re(_R), _Im(_I) {}
  22.     float_complex operator+=(float_complex _R)
  23.         {_Re += _R._Real(), _Im += _R._Imag();
  24.         return (*this); }
  25.     float_complex operator-=(float_complex _R)
  26.         {_Re -= _R._Real(), _Im -= _R._Imag();
  27.         return (*this); }
  28.     float_complex operator*=(float_complex);
  29.     float_complex operator/=(float_complex);
  30.     float _Real() const
  31.         {return (_Re); }
  32.     float _Imag() const
  33.         {return (_Im); }
  34. private:
  35.     float _Re, _Im;
  36.     };
  37.         // class double_complex
  38. class double_complex {
  39. public:
  40.     double_complex(double _R = 0, double _I = 0)
  41.         : _Re(_R), _Im(_I) {}
  42.     double_complex operator+=(double_complex _R)
  43.         {_Re += _R._Real(), _Im += _R._Imag();
  44.         return (*this); }
  45.     double_complex operator-=(double_complex _R)
  46.         {_Re -= _R._Real(), _Im -= _R._Imag();
  47.         return (*this); }
  48.     double_complex operator*=(double_complex);
  49.     double_complex operator/=(double_complex);
  50.     double _Real() const
  51.         {return (_Re); }
  52.     double _Imag() const
  53.         {return (_Im); }
  54. private:
  55.     double _Re, _Im;
  56.     };
  57.         // class long_double_complex
  58. class long_double_complex {
  59. public:
  60.     long_double_complex(long double _R = 0, long double _I = 0)
  61.         : _Re(_R), _Im(_I) {}
  62.     long_double_complex operator+=(long_double_complex _R)
  63.         {_Re += _R._Real(), _Im += _R._Imag();
  64.         return (*this); }
  65.     long_double_complex operator-=(long_double_complex _R)
  66.         {_Re -= _R._Real(), _Im -= _R._Imag();
  67.         return (*this); }
  68.     long_double_complex operator*=(long_double_complex);
  69.     long_double_complex operator/=(long_double_complex);
  70.     long double _Real() const
  71.         {return (_Re); }
  72.     long double _Imag() const
  73.         {return (_Im); }
  74. private:
  75.     long double _Re, _Im;
  76.     };
  77.         // type definitions
  78. typedef float_complex _FC;
  79. typedef double_complex _DC;
  80. typedef long_double_complex _LDC;
  81.         // float_complex functions
  82. inline float imag(_FC _X)
  83.     {return (_X._Imag()); }
  84. inline float real(_FC _X)
  85.     {return (_X._Real()); }
  86. inline _FC _float_complex(const _DC& _X)
  87.     {return (_FC((float)_X._Real(), (float)_X._Imag())); }
  88. inline _FC _float_complex(const _LDC& _X)
  89.     {return (_FC((float)_X._Real(), (float)_X._Imag())); }
  90. inline _FC operator+(_FC _L, _FC _R)
  91.     {return (_L += _R); }
  92. inline _FC operator+(_FC _L, float _R)
  93.     {return (_L += _R); }
  94. inline _FC operator+(float _L, _FC _R)
  95.     {return (_FC(_L) += _R); }
  96. inline _FC operator-(_FC _L, _FC _R)
  97.     {return (_L -= _R); }
  98. inline _FC operator-(_FC _L, float _R)
  99.     {return (_L -= _R); }
  100. inline _FC operator-(float _L, _FC _R)
  101.     {return (_FC(_L) -= _R); }
  102. inline _FC operator*(_FC _L, _FC _R)
  103.     {return (_L *= _R); }
  104. inline _FC operator*(_FC _L, float _R)
  105.     {return (_L *= _R); }
  106. inline _FC operator*(float _L, _FC _R)
  107.     {return (_FC(_L) *= _R); }
  108. inline _FC operator/(_FC _L, _FC _R)
  109.     {return (_L /= _R); }
  110. inline _FC operator/(_FC _L, float _R)
  111.     {return (_L /= _R); }
  112. inline _FC operator/(float _L, _FC _R)
  113.     {return (_FC(_L) /= _R); }
  114. inline _FC operator+(_FC _L)
  115.     {return (_L); }
  116. inline _FC operator-(_FC _L)
  117.     {return (_FC(-real(_L), -imag(_L))); }
  118. inline _Bool operator==(_FC _L, _FC _R)
  119.     {return (real(_L) == real(_R) && imag(_L) == imag(_R)); }
  120. inline _Bool operator==(_FC _L, float _R)
  121.     {return (real(_L) == _R && imag(_L) == 0); }
  122. inline _Bool operator==(float _L, _FC _R)
  123.     {return (_L == real(_R) && 0 == imag(_R)); }
  124. inline _Bool operator!=(_FC _L, _FC _R)
  125.     {return (!(_L == _R)); }
  126. inline _Bool operator!=(_FC _L, float _R)
  127.     {return (!(_L == _R)); }
  128. inline _Bool operator!=(float _L, _FC _R)
  129.     {return (!(_L == _R)); }
  130. istream& operator>>(istream&, _FC&);
  131. ostream& operator<<(ostream&, _FC);
  132. float abs(_FC);
  133. float arg(_FC);
  134. inline _FC conj(_FC _X)
  135.     {return (_FC(real(_X), -imag(_X))); }
  136. _FC cos(_FC);
  137. _FC cosh(_FC);
  138. _FC exp(_FC);
  139. _FC log(_FC);
  140. inline float norm(_FC _X)
  141.     {return (real(_X) * real(_X) + imag(_X) * imag(_X)); }
  142. _FC polar(float, float);
  143. _FC pow(_FC, _FC);
  144. _FC pow(_FC, float);
  145. _FC pow(_FC, int);
  146. _FC pow(float, _FC);
  147. _FC sin(_FC);
  148. _FC sinh(_FC);
  149. _FC sqrt(_FC);
  150.         // double_complex functions
  151. inline double imag(_DC _X)
  152.     {return (_X._Imag()); }
  153. inline double real(_DC _X)
  154.     {return (_X._Real()); }
  155. inline _DC _double_complex(const _LDC& _X)
  156.     {return (_DC((double)_X._Real(), (double)_X._Imag())); }
  157. inline _DC operator+(_DC _L, _DC _R)
  158.     {return (_L += _R); }
  159. inline _DC operator+(_DC _L, double _R)
  160.     {return (_L += _R); }
  161. inline _DC operator+(double _L, _DC _R)
  162.     {return (_DC(_L) += _R); }
  163. inline _DC operator-(_DC _L, _DC _R)
  164.     {return (_L -= _R); }
  165. inline _DC operator-(_DC _L, double _R)
  166.     {return (_L -= _R); }
  167. inline _DC operator-(double _L, _DC _R)
  168.     {return (_DC(_L) -= _R); }
  169. inline _DC operator*(_DC _L, _DC _R)
  170.     {return (_L *= _R); }
  171. inline _DC operator*(_DC _L, double _R)
  172.     {return (_L *= _R); }
  173. inline _DC operator*(double _L, _DC _R)
  174.     {return (_DC(_L) *= _R); }
  175. inline _DC operator/(_DC _L, _DC _R)
  176.     {return (_L /= _R); }
  177. inline _DC operator/(_DC _L, double _R)
  178.     {return (_L /= _R); }
  179. inline _DC operator/(double _L, _DC _R)
  180.     {return (_DC(_L) /= _R); }
  181. inline _DC operator+(_DC _L)
  182.     {return (_L); }
  183. inline _DC operator-(_DC _L)
  184.     {return (_DC(-real(_L), -imag(_L))); }
  185. inline _Bool operator==(_DC _L, _DC _R)
  186.     {return (real(_L) == real(_R) && imag(_L) == imag(_R)); }
  187. inline _Bool operator==(_DC _L, double _R)
  188.     {return (real(_L) == _R && imag(_L) == 0); }
  189. inline _Bool operator==(double _L, _DC _R)
  190.     {return (_L == real(_R) && 0 == imag(_R)); }
  191. inline _Bool operator!=(_DC _L, _DC _R)
  192.     {return (!(_L == _R)); }
  193. inline _Bool operator!=(_DC _L, double _R)
  194.     {return (!(_L == _R)); }
  195. inline _Bool operator!=(double _L, _DC _R)
  196.     {return (!(_L == _R)); }
  197. istream& operator>>(istream&, _DC&);
  198. ostream& operator<<(ostream&, _DC);
  199. double abs(_DC);
  200. double arg(_DC);
  201. inline _DC conj(_DC _X)
  202.     {return (_DC(real(_X), -imag(_X))); }
  203. _DC cos(_DC);
  204. _DC cosh(_DC);
  205. _DC exp(_DC);
  206. _DC log(_DC);
  207. inline double norm(_DC _X)
  208.     {return (real(_X) * real(_X) + imag(_X) * imag(_X)); }
  209. _DC polar(double, double);
  210. _DC pow(_DC, _DC);
  211. _DC pow(_DC, double);
  212. _DC pow(_DC, int);
  213. _DC pow(double, _DC);
  214. _DC sin(_DC);
  215. _DC sinh(_DC);
  216. _DC sqrt(_DC);
  217.         // long_double_complex functions
  218. inline long double imag(_LDC _X)
  219.     {return (_X._Imag()); }
  220. inline long double real(_LDC _X)
  221.     {return (_X._Real()); }
  222. inline _LDC operator+(_LDC _L, _LDC _R)
  223.     {return (_L += _R); }
  224. inline _LDC operator+(_LDC _L, long double _R)
  225.     {return (_L += _R); }
  226. inline _LDC operator+(long double _L, _LDC _R)
  227.     {return (_LDC(_L) += _R); }
  228. inline _LDC operator-(_LDC _L, _LDC _R)
  229.     {return (_L -= _R); }
  230. inline _LDC operator-(_LDC _L, long double _R)
  231.     {return (_L -= _R); }
  232. inline _LDC operator-(long double _L, _LDC _R)
  233.     {return (_LDC(_L) -= _R); }
  234. inline _LDC operator*(_LDC _L, _LDC _R)
  235.     {return (_L *= _R); }
  236. inline _LDC operator*(_LDC _L, long double _R)
  237.     {return (_L *= _R); }
  238. inline _LDC operator*(long double _L, _LDC _R)
  239.     {return (_LDC(_L) *= _R); }
  240. inline _LDC operator/(_LDC _L, _LDC _R)
  241.     {return (_L /= _R); }
  242. inline _LDC operator/(_LDC _L, long double _R)
  243.     {return (_L /= _R); }
  244. inline _LDC operator/(long double _L, _LDC _R)
  245.     {return (_LDC(_L) /= _R); }
  246. inline _LDC operator+(_LDC _L)
  247.     {return (_L); }
  248. inline _LDC operator-(_LDC _L)
  249.     {return (_LDC(-real(_L), -imag(_L))); }
  250. inline _Bool operator==(_LDC _L, _LDC _R)
  251.     {return (real(_L) == real(_R) && imag(_L) == imag(_R)); }
  252. inline _Bool operator==(_LDC _L, long double _R)
  253.     {return (real(_L) == _R && imag(_L) == 0); }
  254. inline _Bool operator==(long double _L, _LDC _R)
  255.     {return (_L == real(_R) && 0 == imag(_R)); }
  256. inline _Bool operator!=(_LDC _L, _LDC _R)
  257.     {return (!(_L == _R)); }
  258. inline _Bool operator!=(_LDC _L, long double _R)
  259.     {return (!(_L == _R)); }
  260. inline _Bool operator!=(long double _L, _LDC _R)
  261.     {return (!(_L == _R)); }
  262. istream& operator>>(istream&, _LDC&);
  263. ostream& operator<<(ostream&, _LDC);
  264. long double abs(_LDC);
  265. long double arg(_LDC);
  266. inline _LDC conj(_LDC _X)
  267.     {return (_LDC(real(_X), -imag(_X))); }
  268. _LDC cos(_LDC);
  269. _LDC cosh(_LDC);
  270. _LDC exp(_LDC);
  271. _LDC log(_LDC);
  272. inline long double norm(_LDC _X)
  273.     {return (real(_X) * real(_X) + imag(_X) * imag(_X)); }
  274. _LDC polar(long double, long double);
  275. _LDC pow(_LDC, _LDC);
  276. _LDC pow(_LDC, long double);
  277. _LDC pow(_LDC, int);
  278. _LDC pow(long double, _LDC);
  279. _LDC sin(_LDC);
  280. _LDC sinh(_LDC);
  281. _LDC sqrt(_LDC);
  282.  
  283. #if __MWERKS__
  284. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  285. #pragma import reset
  286. #endif
  287.  
  288. #pragma options align=reset
  289. #endif
  290.  
  291. #endif
  292.  
  293. /*
  294.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  295.  * Consult your license regarding permissions and restrictions.
  296.  */
  297.  
  298. /* Change log:
  299.  *94June04 PlumHall baseline
  300.  *94Oct07 Inserted MW changes.
  301.  */
  302.